# gozerbot/more.py
#
#

""" cache bot output """

__copyright__ = 'this file is in the public domain'
__credits__ = 'thanks to jemfinch <jemfinch at users.sf.net>'

from gozerbot.dol import Dol

class More(Dol):

    """ more class is a dict of lists .. index is on nick name"""

    def size(self, nick):
        """ return size of nick's more """
        return len(self[nick.lower()])

    def all(self, nick):
        """ return all items of nick """
        nick = nick.lower()
        result = []
        if self.has_key(nick):
            result = self[nick]
        return result

    def pop(self, nick):
        """ pop item from nick's more """
        if repr(nick).find('socket') != -1:
            return
        nick = nick.lower()
        result = None
        if self.has_key(nick):
            try:
                result = self[nick].pop(0)
            except IndexError:
                pass
        return result

    def set(self, nick, listoftxt):
        """ set nick's more item to listoftxt """
        self[nick.lower()] = list(listoftxt)

    def clear(self, nick):
        """ clear nick's item """
        nick = nick.lower()
        if self.has_key(nick):
            self[nick] = []
